package cn.hxzy.teacher.controller;

import cn.hxzy.common.domain.ClassTable;
import cn.hxzy.common.domain.TaskManager;
import cn.hxzy.common.domain.User;
import cn.hxzy.common.domain.vo.TaskUser;
import cn.hxzy.common.response.R;
import cn.hxzy.common.util.ThreadLocalUtil;
import cn.hxzy.teacher.service.TaskManagerService01;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/taskManager01")
public class TaskManagerController01 {

    @Autowired
    private TaskManagerService01 taskManagerService01;
    //根据id主键查询作业详情
    @RequestMapping("/getTaskManagerById/{id}")
    public R getTaskManager(@PathVariable Integer id){
        TaskManager taskManager =null;
        try {
            taskManager = taskManagerService01.getTaskManager(id);
        }catch (Exception e){
            e.printStackTrace();
        }
        return R.success(taskManager);
    }

    @RequestMapping("/taskuser")
    public R selectTaskUser(@RequestBody TaskUser taskUser){
        return R.success(taskManagerService01.selectTaskUser(taskUser));
    }

    //批改作业
    @RequestMapping("/updateTaskManager")
    public R updateTaskManager(@RequestBody Map map){
        int i = taskManagerService01.updatetaskManager(map);
        if (i>0){
            return R.success("批改成功");
        }else {
            return R.error(null);
        }
    }
    // 查询 章节 小节
    @RequestMapping("/and")
    public R seectChapterAndSection(@RequestBody TaskUser taskUser){
        return R.success(taskManagerService01.seectChapterAndSection(taskUser));
    }

    //查询班级
    @GetMapping("/selectClassNameById/{id}")
    public R selectClassNameById(@PathVariable Integer id){
        return R.success(taskManagerService01.selectClassNameById(id));
    }

    //查询布置作业的时间
    @GetMapping("/selectTimeById/{id}")
    public R selectTimeById(@PathVariable Integer id){
        return R.success(taskManagerService01.selectTimeById(id));
    }

    @GetMapping("/banji/{tid}")
    public R banji(@PathVariable("tid") Long tid){
        List<ClassTable> banji = taskManagerService01.banji(tid);
        return R.success(banji);
    }
}
